/*!
 * \file thread.cpp
 * \brief contains a generic thread implementation
 * \author Xavier SCHMERBER
 * \version 1
 */

#include "thread.hh"

Thread::Thread()
{
    _started = false;
}

Thread::~Thread()
{
    destroyThread();
}

bool Thread::createThread(void *(*func)(void *), void *param)
{
    if (0 == pthread_create(&_thread, NULL, func, param))
    {
        _started = true;
        return (true);
    }
    return (false);
}

bool Thread::joinThread()
{
    if (_started == false)
        return (true);
    if (0 == pthread_join(_thread, NULL))
        return (true);
    return (false);
}

bool Thread::destroyThread()
{
    if (_started == false)
        return (true);
    if (0 == pthread_cancel(_thread))
    {
        _started = false;
        return (true);
    }
    return (false);
}
